/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package inventory;

import com.reddys.rad.inventory.utils.ReportUtils;
import com.reddys.rad.inventory.utils.Utilities;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;

/**
 *
 * @author REDDYS
 */
public class IndexController implements Initializable {
    
    Logger log = Utilities.getLogger(IndexController.class.getName());
    @FXML
    private AnchorPane contentPane;
    
    @FXML
    private void handleButtonAction(ActionEvent event) {

    }
    
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    } 
    
    @FXML
    private void menuPurchaseOrder(ActionEvent event) {
            showContentPane("PurchaseOrder1.fxml");
  
    }
      
    @FXML
    private void menuPurchase(ActionEvent event) {
  
            showContentPane("Purchase.fxml");
 
    }
   
    @FXML
    private void menuProduct(ActionEvent event) {
 
            showContentPane("productmaster.fxml");
            
        
    }   
    
    @FXML
    private void menuSales(ActionEvent event) {
      
            showContentPane("Sales.fxml");
      
    }   
        
    @FXML
    private void menuSalesReturn(ActionEvent event) {
  
            showContentPane("SalesReturn.fxml");
     
    }
    @FXML
    private void menuProductCategory(ActionEvent event) {
 
            showContentPane("productcategory.fxml");
  
    }   
    
        @FXML
    private void menuPurchaseReturn(ActionEvent event) {
   
            showContentPane("purchaseReturn.fxml");
       
    } 
        
        @FXML
    private void menuVendor(ActionEvent event) {
  
            showContentPane("vendormaster.fxml");
 
    }
        
    @FXML
    private void menuStockManagement(ActionEvent event) {
   
            showContentPane("stockManagement.fxml");
  
    }
        
    @FXML
    private void menuStockMovement(ActionEvent event) {
    
            showContentPane("stockMovement.fxml");
    
    } 
        
        
    @FXML
    private void ShowPurchaseReport(){
        showReport("purchase_details.jasper");

    }
    
    @FXML
    private void ShowSalesReport(){
      showReport("sales_details.jasper");
    }
    
    @FXML
    private void ShowPurchaseOrderReport(){
      showReport("Purchase_order_details.jasper");
    }
      
    @FXML
    private void ShowStockReport(){
      showReport("stock_details.jasper");
    }
    
    private void showReport(String jasperName){
        try {
            URL url = IndexController.class.getResource(jasperName);
            System.out.println(url.getPath());
            System.out.println(url.getFile());
            ReportUtils rpt  = new ReportUtils();
            rpt.callReport(url.openStream(), null);
        } catch (IOException ex) {
            Logger.getLogger(IndexController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public AnchorPane getContentPane(){
        //contentPane = new AnchorPane();
        return this.contentPane;
    }
    
    public void showContentPane(String sURL){
        try{
        URL url = IndexController.class.getResource(sURL);
        System.out.println(url.getPath());
        log.info(sURL);
        log.info(url.getPath());
        getContentPane().getChildren().clear();
        AnchorPane  n = (AnchorPane) FXMLLoader.load(url, null);
        AnchorPane.setTopAnchor(n, 0.0);
        AnchorPane.setBottomAnchor(n, 0.0);
        AnchorPane.setLeftAnchor(n, 0.0);
        AnchorPane.setRightAnchor(n, 0.0);
        
        getContentPane().getChildren().add(n);
        }catch(Exception e){
            log.info(e.getMessage()+"loca-->"+e.getCause()+"path-------->"+new File("").getAbsolutePath());
        }
    }
}
